<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MCP助手</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/styles.css">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3 col-lg-2 d-md-block bg-light sidebar">
                <div class="position-sticky pt-3">
                    <h5 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
                        <span>MCP助手</span>
                    </h5>
                    <div class="px-3 py-2">
                        <div class="mb-2">
                            <strong>可用服务器:</strong>
                        </div>
                        <ul class="list-unstyled">
                            {% for server in servers %}
                            <li class="mb-1">
                                <span class="{% if server.isConnected %}text-success{% else %}text-muted{% endif %}">
                                    {{ server.description }}
                                    {% if server.isConnected %}
                                    <span class="badge bg-success">已连接</span>
                                    {% else %}
                                    <span class="badge bg-secondary">未连接</span>
                                    {% endif %}
                                </span>
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                    <hr>
                    <div class="px-3 py-2">
                        <p class="text-muted small">
                            系统会根据您的问题自动选择合适的工具，无需手动指定服务器。
                        </p>
                    </div>
                </div>
            </div>

            <!-- 主要内容区 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">智能对话助手</h1>
                    <div class="btn-toolbar mb-2 mb-md-0">
                        <div class="btn-group me-2">
                            <button type="button" class="btn btn-sm btn-outline-danger" id="clearChat">清空对话</button>
                        </div>
                    </div>
                </div>
                
                <!-- 显示当前使用的服务器 -->
                <div id="currentServerInfo" class="alert alert-info mb-3" style="display: none;">
                    当前服务器: <span class="badge bg-primary"></span>
                </div>

                <!-- 聊天区域 -->
                <div class="chat-container mb-3" id="chatContainer">
                    <!-- 初始提示 -->
                    <div class="welcome-message text-center py-5">
                        <h3>欢迎使用MCP智能助手</h3>
                        <p class="text-muted">
                            请输入您的问题，助手会自动选择合适的工具帮您解决问题。
                        </p>
                    </div>
                </div>

                <!-- 输入区域 -->
                <div class="input-group mb-3">
                    <input type="text" class="form-control" id="userInput" placeholder="请输入您的问题...">
                    <button class="btn btn-primary" type="button" id="sendButton">发送</button>
                </div>
            </main>
        </div>
    </div>

    <!-- 工具调用模态框 -->
    <div class="modal fade" id="toolCallModal" tabindex="-1" aria-labelledby="toolCallModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="toolCallModalLabel">工具调用详情</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body" id="toolCallDetails">
                    <!-- 工具调用详情将在这里显示 -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script src="/static/app.js"></script>
</body>
</html>